home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / gs24src.zip / GP_IWATC.C < prev    next >
C/C++ Source or Header  |  1992-03-21  |  3KB  |  94 lines

  1. /* Copyright (C) 1991, 1992 Aladdin Enterprises.  All rights reserved.
  2.    Distributed by Free Software Foundation, Inc.
  3.  
  4. This file is part of Ghostscript.
  5.  
  6. Ghostscript is distributed in the hope that it will be useful, but
  7. WITHOUT ANY WARRANTY.  No author or distributor accepts responsibility
  8. to anyone for the consequences of using it or for whether it serves any
  9. particular purpose or works at all, unless he says so in writing.  Refer
  10. to the Ghostscript General Public License for full details.
  11.  
  12. Everyone is granted permission to copy, modify and redistribute
  13. Ghostscript, but only under the conditions described in the Ghostscript
  14. General Public License.  A copy of this license is supposed to have been
  15. given to you along with Ghostscript so you can know your rights and
  16. responsibilities.  It should be in a file named COPYING.  Among other
  17. things, the copyright notice and this notice must be preserved on all
  18. copies.  */
  19.  
  20. /* gp_iwatc.c */
  21. /* Intel processor, Watcom C-specific routines for Ghostscript */
  22. #include "dos_.h"
  23. #include <fcntl.h>
  24. #include <signal.h>
  25. #include <stdlib.h>
  26. #include "stat_.h"
  27. #include "string_.h"
  28. #include "gx.h"
  29. #include "gp.h"
  30.  
  31. /* Define the size of the C stack. */
  32. unsigned _stklen = 8000;        /* default is 4096, we need more */
  33.  
  34. /* Forward declarations */
  35. private void handle_FPE(P1(int));
  36.  
  37. extern void gp_init_console(P0());
  38. void
  39. gp_init()
  40. {    _fmode = O_BINARY;        /* Open files in 'binary' mode */
  41.     /* Set up the handler for numeric exceptions. */
  42.     signal(SIGFPE, handle_FPE);
  43.     gp_init_console();
  44. }
  45.  
  46. /* Trap numeric exceptions.  Someday we will do something */
  47. /* more appropriate with these. */
  48. private void
  49. handle_FPE(int sig)
  50. {    eprintf("Numeric exception:\n");
  51.     exit(1);
  52. }
  53.  
  54. /* ------ File names ------ */
  55.  
  56. /* Create and open a scratch file with a given name prefix. */
  57. /* Write the actual file name at fname. */
  58. FILE *
  59. gp_open_scratch_file(const char *prefix, char *fname, const char *mode)
  60. {    /* Unfortunately, Watcom C doesn't provide mktemp, */
  61.     /* so we have to simulate it ourselves. */
  62.     struct stat fst;
  63.     char *end;
  64.     strcpy(fname, prefix);
  65.     strcat(fname, "AA.AAA");
  66.     end = fname + strlen(fname) - 1;
  67.     while ( stat(fname, &fst) == 0 )
  68.        {    char *inc = end;
  69.         while ( *inc == 'Z' || *inc == '.' )
  70.            {    if ( *inc == 'Z' ) *inc = 'A';
  71.             inc--;
  72.             if ( end - inc == 6 ) return 0;
  73.            }
  74.         ++*inc;
  75.        }
  76.     return fopen(fname, mode);
  77. }
  78.  
  79. /* ------ File operations ------ */
  80.  
  81. /* If the file given by fname exists, fill in its status and return 1; */
  82. /* otherwise return 0. */
  83. int
  84. gp_file_status(const char *fname, file_status *pstatus)
  85. {    struct stat fst;
  86.     if ( stat(fname, &fst) < 0 ) return 0;
  87.     pstatus->size_pages = (fst.st_size + 1023) >> 10;
  88.     pstatus->size_bytes = fst.st_size;
  89.     /****** CONVERSION PROBABLY REQUIRED HERE ******/
  90.     pstatus->time_referenced = fst.st_atime;
  91.     pstatus->time_created = fst.st_mtime;
  92.     return 1;
  93. }
  94.